package com.general.app.wjgl.service.impl;

import com.general.app.wjgl.dao.IFactorDao;
import com.general.app.wjgl.dao.entity.Factor;
import com.general.app.wjgl.service.IFactorService;
import com.general.common.service.impl.BaseServiceImpl;
import com.general.utils.base.StringUtil;
import com.general.utils.base.UuidUtil;

/**
 * 问卷因子
 * @author Administrator
 *
 */
public class FactorServiceImpl extends BaseServiceImpl<Factor, IFactorDao> implements IFactorService{

	/*
	 * (non-Javadoc)
	 * @see com.general.app.wjgl.service.IFactorService#getFactorByName(java.lang.String)
	 */
	public Factor getFactorByName(String factorName) {
		
		if (StringUtil.isEmpty(factorName)){
			throw new NullPointerException();
		}
		
		Factor factor = dao.getFactorByName(factorName);
		
		if (factor != null && !StringUtil.isEmpty(factor.getId())){
			return factor;
		}
		
		Factor f = new Factor();
		f.setId(UuidUtil.getInstance().getUniqID());
		f.setName(factorName);
		
		int c = dao.insert(f);
		
		return c > 0 ? f : null;
	}

}
